﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
using System.Xml.Linq;

using GaleSong.UI;

namespace GaleSong
{
    public interface IMainService 
    {
        IPage CurrentPage { get; set; }
    }

    public class MainService : BindableBase, IMainService
    {
        #region Field

        private IPage _currentPage;
        private IWorkbench _workbench;

        #endregion

        #region Constructor

        public MainService()
        {
        }

        #endregion

        #region Property

        [Import(typeof(IWorkbench))]
        public IWorkbench Workbench
        {
            get { return _workbench; }
            set
            {
                _workbench = value;
                CurrentPage = value != null && value.Pages.Items.Count > 0 ? value.Pages.Items[0] : null;
            }
        }

        public IPage CurrentPage
        {
            get { return _currentPage; }
            set
            {
                if (_currentPage != value)
                {
                    var page = value as PageBase;
                    if (page != null && page.Content == null)
                    {
                        return;  // 无Content不切换。
                    }

                    _currentPage = value;
                    NotifyPropertyChanged(() => CurrentPage);
                }
            }
        }


        #endregion

        #region Method

        #endregion
    }
}